package top.wshape1.shiziapi.uaa.utils;

import org.springframework.http.HttpStatus;
import top.wshape1.shiziapi.common.exception.StatusCodeException;
import top.wshape1.shiziapi.common.utils.Base64Util;
import top.wshape1.shiziapi.uaa.domain.User;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-09-05
 */

public class UserUtil {

    public static User getFromEncodedString(String userEncoded) {
        User user;
        try {
            user = Base64Util.decodeAndParse(userEncoded, User.class);
        } catch (Exception e) {
            throw new StatusCodeException(HttpStatus.UNAUTHORIZED.value());
        }
        if (user == null || user.getId() == null)
            throw new StatusCodeException(HttpStatus.UNAUTHORIZED.value());

        return user;
    }

}
